package buildcode.language.es.command;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import buildcode.build.AbstractSingleTableCommandExecuter;
import buildcode.config.EntityExportConfig;
import buildcode.database.DataBaseTable;
import buildcode.language.Type;
import buildcode.language.es.EsUtil;
import buildcode.language.es.field.EsField;
import buildcode.language.es.type.EsEntity;

public class EsCommandExecute extends AbstractSingleTableCommandExecuter {

    @Override
    public List<Type> execute(DataBaseTable base, EntityExportConfig config) {
        EsEntity entity = new EsEntity(StringUtils.firstNonBlank(config.getFileName(), base.getCamelCaseName() + config.getSuffix()), config.getPackageName());
        base.getColumns().stream().forEach(column -> {
            entity.addField(new EsField(column.getCamelCaseName(), EsUtil.getEsTypeByJdbcType(column.getJdbcType()), "", column));
        });
        return Arrays.asList(entity);
    }

}
